package com.stek.settings;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.stek.R;
import com.stek.model.Wifi;

public class TrustWifiAdapter extends BaseAdapter {
	private ArrayList<Wifi> wifis;
	private Context context;

	public TrustWifiAdapter(ArrayList<Wifi> wifis, Context context) {
		super();
		this.wifis = wifis;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return wifis.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return wifis.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;

		Wifi wifi = wifis.get(position);
		if (null == convertView) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.row_common4, null);
			holder = new Holder();
			holder.tvName = (TextView) convertView.findViewWithTag(context
					.getString(R.string.tag_name));
			holder.tvDesc = (TextView) convertView.findViewWithTag(context
					.getString(R.string.tag_desc));
			holder.imgIcon = (ImageView) convertView.findViewWithTag(context
					.getString(R.string.tag_icon));
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		if (wifi.trust) {
			holder.imgIcon.setImageResource(R.drawable.ic_wifi_trust);
			holder.tvName.setTextColor(context.getResources().getColor(R.color.blue));
		} else {
			holder.imgIcon.setImageResource(R.drawable.ic_wifi_untrust);
			holder.tvName.setTextColor(context.getResources().getColor(R.color.black));
		}
		holder.tvName.setText(wifi.SSID);
		holder.tvDesc.setText(String.format("%s  %s", wifi.BSSID,
				wifi.trust ? context.getString(R.string.trust) : ""));
		return convertView;
	}

	static class Holder {
		TextView tvName;
		TextView tvDesc;
		ImageView imgIcon;
	}

}
